﻿@model Cxuu.Models.EditAdminUserGroup
@{
    ViewData["Title"] = "保存";
}
<div class="content-top-nav">
    <div class="layui-row">
        <div class="layui-col-md11">
            <h3 style="color:#444">
                <i class="layui-icon layui-icon-home"></i>
                角色编辑
            </h3>
        </div>
        <div class="layui-col-md1" style="text-align:right;">
            <button class="layui-btn layui-btn-sm" onclick="loadMain('/Admin/UserGroup/Index')">返回列表</button>
        </div>
    </div>
    <hr>
</div>

<div class="layui-fluid" style="margin-bottom:50px;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <blockquote class="layui-elem-quote">修改角色权限后，用户不用重新登录，立即生效！</blockquote>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form">
        <form class="layui-form" action="" lay-filter="FormEdit" enctype="multipart/form-data">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <fieldset class="layui-elem-field">
                <legend><label asp-for="Groupname" class="layui-form-label"></label></legend>
                <div class="layui-field-box">
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <input type="text" asp-for="Groupname" value="" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">角色名</div>
                    </div>
                </div>
            </fieldset>

            <fieldset class="layui-elem-field">
                <legend>系统权限</legend>
                <div class="layui-field-box">


                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                        <legend><label asp-for="Systemrole" class="layui-form-label"></label></legend>
                    </fieldset>


                    <div class="layui-form-item">
                        <label class="layui-form-label">模块功能</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Menu_Index)" title="后台主页" checked disabled>
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Menu_Article)" title="办公管理">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Menu_System)" title="系统管理">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Menu_Content)" title="网站管理">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Statistics_Index)" title="工作统计">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">系统设置</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Config_Index)" title="查看">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Config_Edit)" title="编辑">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">操作日志</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Log_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Log_Clear)" title="清除">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">缓存管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Cache_Index)" title="列表">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">通知管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Notice_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Notice_AddOrEdit)" title="发布">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Notice_Delete)" title="删除">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">附件管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Upload_Upload)" title="上传">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Attment_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Attment_AddOrEdit)" title="添加">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Attment_Delete)" title="删除">
                        </div>
                    </div>
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                        <legend>权限管理</legend>
                    </fieldset>
                    <div class="layui-form-item">
                        <label class="layui-form-label">部门管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserDept_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserDept_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserDept_Delete)" title="删除">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserDept_Resource)" title="资源管理">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">岗位管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserPost_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserPost_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserPost_Delete)" title="删除">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.User_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.User_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.User_Delete)" title="删除">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.User_UserChange)" title="修改个人信息">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">角色管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserGroup_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserGroup_AddOrEdit)" title="添加/编辑">                            
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.UserGroup_Delete)" title="删除">
                        </div>
                    </div>
                    
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                        <legend>办公管理</legend>
                    </fieldset>
                    <div class="layui-form-item">
                        <label class="layui-form-label">类别管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Category_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Category_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Category_Delete)" title="删除">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">报送管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Article_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Article_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Article_Delete)" title="删除">
                        </div>  
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleExamine_Post)" title="提交审核">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleExamine_Index)" title="审核列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleExamine_Update)" title="审核内容">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">来文管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleDocreceived_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleDocreceived_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleDocreceived_Delete)" title="删除">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">工作报表</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleStatement_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleStatement_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ArticleStatement_Delete)" title="删除">
                        </div>
                    </div>

                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                        <legend>网站管理</legend>
                    </fieldset>
                    <div class="layui-form-item">
                        <label class="layui-form-label">栏目管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ContentCate_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ContentCate_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.ContentCate_Delete)" title="删除">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容管理</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Content_Index)" title="列表">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Content_AddOrEdit)" title="添加/编辑">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Content_Delete)" title="删除">
                            <input type="checkbox" name="Systemrole" value="@(PermissionKeys.Content_Status)" title="属性设置">
                        </div>
                    </div>
                </div>
            </fieldset>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input asp-for="Id" value="" class="layui-input" type="hidden">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn" id="saveBtn"><i class="layui-icon">&#xe605;</i>@ViewData["Title"]</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.define(function () {
        var form = layui.form, layer = layui.layer, $ = layui.jquery;

        form.render();

        var editId = @ViewBag.id+1;
        if (editId > 1) {
            $.getJSON("/Admin/UserGroup/AddOrEdit?id=@ViewBag.id&edit=1&json=1", function (res) {
                if (res.status == 1) {
                    form.val('FormEdit', {
                       "Id": res.data.id,
                        "Groupname": res.data.groupname,
                        //"Systemrole": res.data.systemrole,
                        //"Channlrole": res.data.channlrole,
                    });
                    //复选框选中
                    var data = JSON.parse(res.data.systemrole);
                    //console.log("data:", res);
                    $.each(data, (v) => {
                        let node = $(`input[type="checkbox"][name^="Systemrole"][value="${data[v]}"]`);
                        if (node && node.length) {
                            node[0].checked = true;
                            form.render('checkbox');
                        }
                    });
                }
            });
        }

        var dataPost = function (url, data) {
            $.post(url, data, function (res) {
                if (res.status == 1) {
                    $("#saveBtn").hide();
                    layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                        loadMain('/Admin/UserGroup/Index/');
                    });
                } else {
                    layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                }
            });
        }

        //监听提交
        $('#saveBtn').click(function () {
            var field = form.val('FormEdit');

            quotation = new Array();
            $("input:checkbox[name='Systemrole']:checked").each(function () {
                quotation.push($(this).val());
            });
            var SystemroleJson = JSON.stringify(quotation);

            var post = {
                Id: field.Id == null ? 0 : field.Id,
                Groupname: field.Groupname,
                Systemrole: SystemroleJson,
            };

            if (editId == 1)
                dataPost('/Admin/UserGroup/CreatePost', post);
            else
                dataPost('/Admin/UserGroup/EditPost?id=@ViewBag.id', post);
            return false;
        });
    });

</script>